package Song.Han.Demo01;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/*
    接收客户端请求
    构造方法：
        ServerSocket(int port)创建绑定到特定端口的服务器套接字
    成员方法：
        Socket accept() 侦听并接受此套接字的连接
*/
public class TCPServer {
    public static void main(String[] args) throws IOException {

        ServerSocket server = new ServerSocket(8888);

        Socket s = server.accept();

        InputStream is = s.getInputStream();
        byte[] bytes = new byte[1024];
        int len = is.read(bytes);
        System.out.println(new String(bytes,0,len));

        OutputStream os = s.getOutputStream();
        os.write("收到，谢谢".getBytes());

        s.close();
        server.close();
    }
}
